<?php

namespace common\models;

use Yii;

/**
 * This is the model class for table "profile".
 *
 * @property integer $user_id
 * @property string $name
 * @property string $surname
 * @property string $avatar_url
 * @property integer $sex
 * @property string $birthday
 * @property integer $country
 * @property integer $province
 * @property integer $city
 * @property integer $district
 *
 * @property User $user
 */
class Profile extends \yii\db\ActiveRecord
{
    /**
     * @inheritdoc
     */
    public static function tableName()
    {
        return 'profile';
    }

    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            [['sex', 'country', 'province', 'city', 'district'], 'integer'],
            [['birthday'], 'safe'],
            [['name', 'surname', 'avatar_url'], 'string', 'max' => 64],
            [['user_id'], 'exist', 'skipOnError' => true, 'targetClass' => User::className(), 'targetAttribute' => ['user_id' => 'id']],
        ];
    }

    /**
     * @inheritdoc
     */
    public function attributeLabels()
    {
        return [
            'user_id' => 'User ID',
            'name' => 'Name',
            'surname' => 'Surname',
            'avatar_url' => 'Avatar Url',
            'sex' => 'Sex',
            'birthday' => 'Birthday',
            'country' => 'Country',
            'province' => 'Province',
            'city' => 'City',
            'district' => 'District',
        ];
    }

    /**
     * @return \yii\db\ActiveQuery
     */
    public function getUser()
    {
        return $this->hasOne(User::className(), ['id' => 'user_id']);
    }
}
